<script setup lang="ts">
import { ref } from 'vue'
import { Picture, Microphone, Delete, Plus } from '@element-plus/icons-vue'

interface Milestone {
  title: string
  deadline: string
  completed: boolean
}

const activeTab = ref('diary')
const diaryForm = ref({
  title: '',
  content: '',
  date: new Date(),
  mood: '',
  tags: [] as string[],
  images: [] as string[],
})

const goalForm = ref({
  title: '',
  description: '',
  deadline: '',
  priority: 'medium',
  milestones: [] as Milestone[],
})

const moods = [
  { label: '开心', value: 'happy', icon: '😊' },
  { label: '平静', value: 'calm', icon: '😌' },
  { label: '思考', value: 'thinking', icon: '🤔' },
  { label: '疲惫', value: 'tired', icon: '😫' },
  { label: '兴奋', value: 'excited', icon: '🤩' },
]

const priorities = [
  { label: '高', value: 'high' },
  { label: '中', value: 'medium' },
  { label: '低', value: 'low' },
]

const handleDiarySubmit = () => {
  console.log('提交日记:', diaryForm.value)
  // TODO: 实现日记提交逻辑
}

const handleGoalSubmit = () => {
  console.log('提交目标:', goalForm.value)
  // TODO: 实现目标提交逻辑
}

const addMilestone = () => {
  goalForm.value.milestones.push({
    title: '',
    deadline: '',
    completed: false,
  })
}

const removeMilestone = (index: number) => {
  goalForm.value.milestones.splice(index, 1)
}
</script>

<template>
  <div class="create-container">
    <el-card class="create-card">
      <template #header>
        <div class="card-header">
          <span class="card-title">时空裂缝</span>
          <div class="quick-actions">
            <el-button type="success" :icon="Microphone" circle class="glow-button" />
            <el-button type="warning" :icon="Picture" circle class="glow-button" />
          </div>
        </div>
      </template>

      <el-tabs v-model="activeTab" class="create-tabs">
        <!-- 日记模式 -->
        <el-tab-pane label="日记模式" name="diary">
          <el-form :model="diaryForm" label-position="top" class="create-form">
            <el-form-item label="标题">
              <el-input v-model="diaryForm.title" placeholder="给今天的记录起个标题" />
            </el-form-item>

            <el-form-item label="心情">
              <el-radio-group v-model="diaryForm.mood" class="mood-group">
                <el-radio-button v-for="mood in moods" :key="mood.value" :label="mood.value">
                  <span class="mood-icon">{{ mood.icon }}</span>
                  <span class="mood-label">{{ mood.label }}</span>
                </el-radio-button>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="内容">
              <el-input
                v-model="diaryForm.content"
                type="textarea"
                :rows="6"
                placeholder="记录下此刻的想法..."
                resize="none"
              />
            </el-form-item>

            <el-form-item label="标签">
              <el-select
                v-model="diaryForm.tags"
                multiple
                filterable
                allow-create
                default-first-option
                placeholder="添加标签"
              >
                <el-option
                  v-for="tag in ['生活', '工作', '学习', '思考', '目标']"
                  :key="tag"
                  :label="tag"
                  :value="tag"
                />
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="handleDiarySubmit" class="glow-button">
                保存日记
              </el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <!-- 目标模式 -->
        <el-tab-pane label="目标模式" name="goal">
          <el-form :model="goalForm" label-position="top" class="create-form">
            <el-form-item label="目标名称">
              <el-input v-model="goalForm.title" placeholder="设定一个目标" />
            </el-form-item>

            <el-form-item label="目标描述">
              <el-input
                v-model="goalForm.description"
                type="textarea"
                :rows="3"
                placeholder="详细描述你的目标..."
                resize="none"
              />
            </el-form-item>

            <el-form-item label="截止日期">
              <el-date-picker v-model="goalForm.deadline" type="date" placeholder="选择截止日期" />
            </el-form-item>

            <el-form-item label="优先级">
              <el-radio-group v-model="goalForm.priority" class="priority-group">
                <el-radio-button
                  v-for="priority in priorities"
                  :key="priority.value"
                  :label="priority.value"
                >
                  {{ priority.label }}
                </el-radio-button>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="里程碑">
              <div
                v-for="(milestone, index) in goalForm.milestones"
                :key="index"
                class="milestone-item"
              >
                <el-input v-model="milestone.title" placeholder="里程碑名称" />
                <el-date-picker v-model="milestone.deadline" type="date" placeholder="截止日期" />
                <el-button type="danger" circle @click="removeMilestone(index)">
                  <el-icon><Delete /></el-icon>
                </el-button>
              </div>
              <el-button type="primary" plain @click="addMilestone">
                <el-icon><Plus /></el-icon>
                添加里程碑
              </el-button>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="handleGoalSubmit" class="glow-button">
                创建目标
              </el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<style scoped>
.create-container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.create-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow-shadow);
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  font-size: 20px;
  font-weight: bold;
  background: var(--wormhole-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.quick-actions {
  display: flex;
  gap: 10px;
}

.create-tabs {
  :deep(.el-tabs__nav-wrap::after) {
    background-color: var(--border-color);
  }

  :deep(.el-tabs__item) {
    color: var(--text-secondary);

    &.is-active {
      color: var(--laser-cyan);
    }

    &:hover {
      color: var(--laser-cyan);
    }
  }

  :deep(.el-tabs__active-bar) {
    background-color: var(--laser-cyan);
    height: 2px;
  }
}

.create-form {
  padding: 20px 0;
}

.mood-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;

  :deep(.el-radio-button__inner) {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);

    &:hover {
      background: rgba(0, 255, 209, 0.1);
    }
  }

  :deep(.is-active .el-radio-button__inner) {
    background: var(--laser-cyan);
    border-color: var(--laser-cyan);
    color: var(--quantum-blue);
  }
}

.mood-icon {
  font-size: 20px;
}

.mood-label {
  font-size: 14px;
}

.priority-group {
  :deep(.el-radio-button__inner) {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);

    &:hover {
      background: rgba(0, 255, 209, 0.1);
    }
  }

  :deep(.is-active .el-radio-button__inner) {
    background: var(--laser-cyan);
    border-color: var(--laser-cyan);
    color: var(--quantum-blue);
  }
}

.milestone-item {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}

:deep(.el-input__wrapper),
:deep(.el-textarea__wrapper) {
  background: var(--bg-secondary);
  border-color: var(--border-color);
  box-shadow: none;

  &:hover {
    border-color: var(--laser-cyan);
  }

  &.is-focus {
    border-color: var(--laser-cyan);
    box-shadow: 0 0 0 1px var(--laser-cyan);
  }
}

:deep(.el-input__inner),
:deep(.el-textarea__inner) {
  color: var(--text-primary);

  &::placeholder {
    color: var(--text-tertiary);
  }
}

:deep(.el-select-dropdown) {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);

  .el-select-dropdown__item {
    color: var(--text-primary);

    &.selected {
      color: var(--laser-cyan);
      font-weight: bold;
    }

    &:hover {
      background: rgba(0, 255, 209, 0.1);
    }
  }
}

:deep(.el-date-editor) {
  background: var(--bg-secondary);
  border-color: var(--border-color);

  &:hover {
    border-color: var(--laser-cyan);
  }

  &.is-focus {
    border-color: var(--laser-cyan);
    box-shadow: 0 0 0 1px var(--laser-cyan);
  }
}

.glow-button {
  position: relative;
  overflow: hidden;

  &::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    animation: shine 3s infinite;
  }
}

@keyframes shine {
  0% {
    transform: translateX(-100%) rotate(45deg);
  }
  100% {
    transform: translateX(100%) rotate(45deg);
  }
}
</style>
